package cn.ichiva.dl.tushare.job;

import cn.ichiva.dl.tushare.tu.Config;
import cn.ichiva.dl.tushare.tu.data.Daily;
import cn.ichiva.dl.tushare.tu.data.Shibor;
import cn.ichiva.dl.tushare.tu.data.TradeCal;
import cn.ichiva.dl.tushare.tu.predict.DecisionUtils;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.factory.Nd4j;

/**
 * tushare 环境
 *
 */
public class TuShareEVN {
    private static TuShareEVN instance = new TuShareEVN();
    private final Daily daily;
    private final Shibor shibor;
    private final TradeCal tradeCal;

    public static TuShareEVN getInstance(){
        return instance;
    }

    private TuShareEVN(){
        this.daily = new Daily(Config.tuConfig);
        this.shibor = new Shibor(Config.tuConfig);
        this.tradeCal = new TradeCal(Config.tuConfig);
    }

    public String[] getStockAndRate(String ts_code,String day){
       return DecisionUtils.getStockAndRate(daily,shibor,ts_code,day);
    }

    public Daily getDaily() {
        return daily;
    }

    public Shibor getShibor() {
        return shibor;
    }

    public TradeCal getTradeCal() {
        return tradeCal;
    }

    public INDArray getINDArray(String ts_code, String day) {
        String[] arr = getStockAndRate(ts_code, day);
        double[] tem = new double[arr.length];
        for (int i = 0; i < arr.length; i++) {
            tem[i] = Double.parseDouble(arr[i]);
        }

        return Nd4j.create(tem).reshape(1,17,1);
    }
}
